<?php

class email_reciept_e_order extends a_event_subscriber {

    public function __construct() {
        parent::__construct();
    }

    public function fire($args = null) {
        logger::i()->info("fiering email for order");
        //make objects
        $order = $args;
        $esrv = new service_l_email();
        $user = get_logged_user();
        $email = new email_m_email(true);
        $company = service_l_core::get_company();
        //send email
        $template = $esrv->get_template_by_type(email_types_m_email::ORDER_USER);
        $html = $esrv->render_template($template);
        $email->set_body($html);
        $email->add_from($company->sales_email, $company->name);
        $email->add_to($user->email, $user->username);
        $email->add_cc($company->sales_email, $company->name);
        $email->set_subject($company->name ." Order confirmation");
        //update order
        $esrv->send_mail($email)> 0 ? $order->set_email_sent(1) : $order->set_email_sent(0);
    }

    public function get_event_name() {
        return module_u_order::EVENT_ORDER_PAYMENT_SUCCESS;
    }
}

?>